<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;}
#l-map{height:90%;width:90%;border-right:2px solid #bcbcbc;margin:10px;}
#r-result{height:100%;width:20%;float:left;}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=6RQGXCYLSCZzLuPgZnnSMMrd"></script>
<title>起终点可拖拽的驾车导航</title>
</head>
<body>
<div id="l-map"></div>
<div id="r-result"></div>
</body>
</html>
<script type="text/javascript">

var map = new BMap.Map("l-map");
map.centerAndZoom(new BMap.Point(116.404, 39.915), 12);
//map.setCenter("长沙");

var myCity = new BMap.LocalCity();
myCity.get(function(result){
	var cityName = result.name;
    alert("当前城市为:"+cityName);
});


map.enableScrollWheelZoom();
map.addControl(new BMap.NavigationControl());
map.addControl(new BMap.NavigationControl({anchor: BMAP_ANCHOR_TOP_RIGHT, type: BMAP_NAVIGATION_CONTROL_SMALL}));
map.addControl(new BMap.NavigationControl({anchor: BMAP_ANCHOR_BOTTOM_LEFT, type: BMAP_NAVIGATION_CONTROL_PAN}));
map.addControl(new BMap.NavigationControl({anchor: BMAP_ANCHOR_BOTTOM_RIGHT, type: BMAP_NAVIGATION_CONTROL_ZOOM}));

var output = "";
var searchComplete = function (results){
	
	if (driving.getStatus() != BMAP_STATUS_SUCCESS){
        return false;
    }
	var plan   = results.getPlan(0);
	output  = "";
    output += "时间为:"+plan.getDuration(true) + "\n"; 
    output += "距离为:" ;
    output += plan.getDistance(true) + "\n";
}

/*,selectFirstResult:true,panel: "r-result"*/

var driving = new BMap.DrivingRoute(map, {renderOptions: {map: map,enableDragging : true},
    onSearchComplete: searchComplete,
    onPolylinesSet: function(){        
        alert(output);
	}
});
driving.search("长沙火车站", "中南大学铁道学院");

</script>



